#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int get_digit_sum(int x) {
  int ans = 0;
  while (x) {
    ans += x % 10;
    x /= 10;
  }
  return ans;
}

bool is_good(int x) { return x % get_digit_sum(x) == 0; }

void print0(int n) {
  for (int i = 1; i <= n; ++i) putchar('0');
}

int main() {
  string N;
  cin >> N;
  if (N.length() <= 7) {
    int n = stoi(N);
    for (int a = n; a < 2 * n; ++a)
      if (is_good(a) && is_good(a + 1)) {
        cout << a << endl;
        return 0;
      }
    cout << -1 << endl;
    return 0;
  }
  bool have_nonzero = false;
  for (int i = 1; i < N.length(); ++i) {
    if (N[i] != '0') {
      have_nonzero = true;
      break;
    }
  }

  if (!have_nonzero) {
    int X = N[0] - '0';
    if (X != 9) {
      printf("%d%d", X, 8 - X);
      print0(N.length() - 2);
    } else {
      printf("17");
      print0(N.length() - 1);
    }
  } else {
    int X = N[0] - '0';
    int Y = N[1] - '0';
    if (X == 8) {
      printf("107");
      print0(N.length() - 2);
    } else if (X == 9) {
      printf("17");
      print0(N.length() - 1);
    } else if (X != 1 || (X == 1 && Y >= 5)) {
      printf("%d%d", X + 1, 8 - X - 1);
      print0(N.length() - 2);
    } else {
      // 现在只剩下 X == 1 而且 Y < 5 的情况
      printf("17");
      print0(N.length() - 2);
    }
  }
  return 0;
}